package com.real.operationalcontrols.任务;

import android.os.Bundle;
import android.widget.ImageView;
import android.widget.TextView;

import com.assionhonty.lib.assninegridview.AssNineGridView;
import com.assionhonty.lib.assninegridview.AssNineGridViewClickAdapter;
import com.assionhonty.lib.assninegridview.ImageInfo;
import com.blankj.utilcode.util.ToastUtils;
import com.google.gson.Gson;
import com.real.operationalcontrols.R;
import com.real.operationalcontrols.rxhttp.MyDialogObserver;
import com.real.operationalcontrols.rxhttp.NetworkUrl;
import com.real.operationalcontrols.rxhttp.RxHttpManger;
import com.real.operationalcontrols.基类.BaseActivity;
import com.real.operationalcontrols.实体类.TaskDetialBean;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import butterknife.BindView;
import butterknife.OnClick;

public class TaskFinshActivity extends BaseActivity {

    @BindView(R.id.bar_back_btn)
    ImageView barBackBtn;
    @BindView(R.id.bar_title)
    TextView barTitle;
    @BindView(R.id.bar_check_btn)
    TextView barCheckBtn;
    @BindView(R.id.task_id)
    TextView taskId;
    @BindView(R.id.task_time)
    TextView taskTime;
    @BindView(R.id.task_name)
    TextView taskName;
    @BindView(R.id.task_location_start)
    TextView taskLocationStart;
    @BindView(R.id.task_location_finsh)
    TextView taskLocationFinsh;
    @BindView(R.id.task_txt)
    TextView taskTxt;
    @BindView(R.id.task_beizhu)
    TextView taskBeizhu;
    @BindView(R.id.rv_img_two)
    AssNineGridView rvImgTwo;
    @BindView(R.id.task_address)
    TextView taskAddress;

    String id;
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    ArrayList<ImageInfo> imageInfo_h = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //setContentView(R.layout.activity_task_finsh);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_task_finsh;
    }

    @Override
    protected void getData() {
        id = getIntent().getStringExtra("id");
        barTitle.setText("任务查看");

        Map<String, String> map = new HashMap<>();
        map.put("taskname", id);
        RxHttpManger.getInstance().get(this, NetworkUrl.TASK_DETIAL, map,
                new MyDialogObserver(this) {
                    @Override
                    public void onSuccess(String response) {
                        TaskDetialBean bean = new Gson().fromJson(response, TaskDetialBean.class);
                        if (bean.isSuccess()) {
                            taskId.setText(bean.getTasklist().get(0).getId());
                            taskTime.setText(bean.getTasklist().get(0).getTime());
                            taskAddress.setText(bean.getTasklist().get(0).getAddress());
                            taskName.setText(bean.getTasklist().get(0).getPeople());
                            taskLocationStart.setText(bean.getTasklist().get(0).getLocal_pre());
                            taskLocationFinsh.setText(bean.getTasklist().get(0).getLocal_last());
                            for (int i = 0; i < bean.getTasklist().get(0).getImg_last().size(); i++) {
                                ImageInfo image = new ImageInfo();
                                image.setThumbnailUrl(bean.getTasklist().get(0).getImg_last().get(i).getUrl());
                                image.setBigImageUrl(bean.getTasklist().get(0).getImg_last().get(i).getUrl());
                                imageInfo_h.add(image);
                            }

                            rvImgTwo.setAdapter(new AssNineGridViewClickAdapter(TaskFinshActivity.this,
                                    imageInfo_h));
                            StringBuilder sb = new StringBuilder();
                            for (int i = 0; i < bean.getTasklist().get(0).getContext().size(); i++) {
                                sb.append(bean.getTasklist().get(0).getContext().get(i).getTip()).append("\n");
                            }
                            taskTxt.setText(sb.toString());
                            taskBeizhu.setText(bean.getTasklist().get(0).getLog());
                        } else {
                            ToastUtils.showShort(bean.getMessage());
                        }
                    }
                });

    }

    @OnClick(R.id.bar_back_btn)
    public void onViewClicked() {
        finish();
    }
}
